package com.tianyuan.dplrf.ui.adapter;

import android.content.Context;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;

import com.hjq.base.BaseAdapter;
import com.tianyuan.dplrf.R;
import com.tianyuan.dplrf.app.AppAdapter;
import com.tianyuan.dplrf.ui.bean.NczdBean;
import com.xuexiang.xutil.display.DensityUtils;

import java.util.List;

public class NczdAdapter extends AppAdapter<NczdBean> {

    private  int onitemwith;
    private  int onitemheight;
    private int picheight;
    private int picWith;
    public NczdAdapter(@NonNull Context context, List<NczdBean> list) {
        super(context);
        setData(list);
        onitemwith = (DensityUtils.getScreenWidth() - DensityUtils.dip2px(16+30))/3;
        onitemheight = DensityUtils.getScreenHeight() - DensityUtils.dip2px(60 + 8 + 20);
        picheight = onitemheight - DensityUtils.dip2px(38);
        picWith = onitemwith;
    }

    @NonNull
    @Override
    public BaseAdapter<?>.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends BaseAdapter.ViewHolder{
        private ImageView imgview;
        private CardView card;
        private TextView text_name;
        private LinearLayout contentview;

        public ViewHolder() {
            super(R.layout.item_nczd_adap);
            Log.e("tage", "ViewHolder: " );
            contentview = (LinearLayout) getItemView();
            imgview = getItemView().findViewById(R.id.imgview);
            card = getItemView().findViewById(R.id.card);
            text_name = getItemView().findViewById(R.id.text_name);
        }

        @Override
        public void onBindView(int position) {
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(onitemwith,onitemheight);
//            params.height = onitemheight;
//            params.width = onitemwith;
            contentview.setLayoutParams(params);
            NczdBean data = getItem(position);
            imgview.setImageResource(data.getId());
            text_name.setText(data.getNcName());
        }
    }
}
